package msg.chestionar.ejb.beans;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;



import com.msg.chestionar.entities.UtilizatorE;
import com.msg.chestionar.to.UtilizatorTO;

import msg.chestionar.ejb.bi.UserBI;

@Stateless
public class UserBA implements UserBI {
	
	@PersistenceContext
	private EntityManager em;	

	@Override
	public UtilizatorTO getUser(String username, String password) {
		Query query = em.createNamedQuery("UtilizatorE.findByNameAndPassword");
		query.setParameter("name", username);
		query.setParameter("parola", password);
		if (!query.getResultList().isEmpty()){
			UtilizatorE userE = (UtilizatorE) query.getResultList().get(0);
			return userE.getUtilizatorTO();
		}
		return null;
	}

}
